Slide 14

Binary Tree Representations

Hover over elements to see how they correspond in each representation.

Linked Structure

Each node is an object with a value and pointers (references) to its left and right children. This is intuitive but uses more memory for pointers.

Array Representation

This method flattens the tree into an array by reading the nodes level by level, from left to right (a process called level-order traversal). This is very memory-efficient, as relationships are defined by a node's index, not by pointers.

Parent of index i = floor((i - 1) / 2)
Left child of index i = 2*i + 1
Right child of index i = 2*i + 2